#include "vanguard.h"
#include "ui_vanguard.h"
#include "SpellEffect.h"
#include "Ability.h"
#include "Rotation.h"
#include "RatingConvert.h"
#include "Defense.h"
#include <fstream>

Vanguard::Vanguard(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::Vanguard)
{
    ui->setupUi(this);
    updateStatBoxes();
}

Vanguard::~Vanguard()
{
    delete ui;
}

enum STATS {
    AIM = 0, CUNNING, STRENGTH, WILLPOWER = 3,
    CRIT, SURGE, ALACRITY , POWER , ACCURACY = 8,
    DEFENSE, SHIELD, ABSORB, ARMOR = 12,
    LEVEL, MH_ACC, OH_ACC, ENEMY_LEVEL, ENEMY_ARMOR= 17,
    SPEED,  MH_MAX, MH_MIN, OH_MAX , OH_MIN =22,
    TECH_CRIT_CHANCE , TECH_CRIT_SIZE, TECH_BONUS_HEALING, TECH_BONUS_DAMAGE = 26,
    RANGED_CRIT_CHANCE , RANGED_CRIT_SIZE, RANGED_BONUS_DAMAGE = 29,
    FORCE_CRIT_CHANCE , FORCE_CRIT_SIZE, FORCE_BONUS_HEALING, FORCE_BONUS_DAMAGE = 33,
    MELEE_CRIT_CHANCE , MELEE_CRIT_SIZE, MELEE_BONUS_DAMAGE = 36,
    TECH_POWER, FORCE_POWER = 38
};

//define global Vanguard variables
QString vanRotationOutput;
QString &vanRotationRef = vanRotationOutput;


//create a holder for the stats
std::vector <double> vanStats(39,0);



void Vanguard::setStats()
{
    int accBuff = 0;
    int critBuff = 3*(ui->skillBox_3->value());
    critBuff += 2*(ui->skillBox_2->value());
    if(ui->smugglerCheckBox->isChecked()) critBuff += 5;
    int techSurgeBuff = 3*(ui->skillBox_4->value());
    //int aimUpgBuff = 3*(ui->skillBox_1->value());
    int alacBuff = 2*(ui->skillBox_6->value());
    if(ui->skillBox_5->value()==2) alacBuff += 5;

    int aim = ui->primaryBox->value();
    if(ui->consularCheckBox->isChecked()) aim *= 1.05;

    vanStats.at(AIM) = aim;
    vanStats.at(CUNNING) = ui->secondaryBox->value();
    vanStats.at(CRIT)= ui->critBox->value();
    vanStats.at(SURGE)= ui->surgeBox->value();
    vanStats.at(POWER)= ui->powerBox->value();
    vanStats.at(TECH_POWER) = ui->techBox->value();
    vanStats.at(ALACRITY)= ui->alacBox->value();
    vanStats.at(LEVEL)= ui->levelBox->value();

    vanStats.at(ACCURACY) = ui->accBox->value();
    vanStats.at(MH_MAX) = ui->MHmaxBox->value();
    vanStats.at(MH_MIN) = ui->MHminBox->value();
    vanStats.at(ENEMY_LEVEL) = ui->enemyLevelBox->value();
    vanStats.at(ENEMY_ARMOR) = ui->enemyArmorBox->value();

    vanStats.at(TECH_CRIT_CHANCE) = ( TechCritChance(vanStats, critBuff, true));
    vanStats.at(TECH_CRIT_SIZE) = ( TechCritSize(vanStats, techSurgeBuff));
    vanStats.at(SPEED) =( Speed(vanStats, alacBuff));
    vanStats.at(MH_ACC) = (MH_Accuracy(vanStats, accBuff));
    vanStats.at(TECH_BONUS_DAMAGE) = TechBonusDamage(vanStats, true);
    vanStats.at(RANGED_CRIT_CHANCE) = ( RangedCritChance(vanStats, critBuff, false));
    vanStats.at(RANGED_CRIT_SIZE) = ( RangedCritSize(vanStats, 0));
    vanStats.at(RANGED_BONUS_DAMAGE) = RangedBonusDamage(vanStats, false);

    vanStats.at(ARMOR) = ui->armorBox->value();
    vanStats.at(DEFENSE) = ui->defBox->value();
    vanStats.at(SHIELD) = ui->shieldBox->value();
    vanStats.at(ABSORB) = ui->absorbBox->value();

}

vector <double> Vanguard::calculateStats(vector <double> &stats2){
    int accBuff = 0;
    int critBuff = 3*(ui->skillBox_3->value());
    critBuff += 2*(ui->skillBox_2->value());
    if(ui->smugglerCheckBox->isChecked()) critBuff += 5;
    int techSurgeBuff = 3*(ui->skillBox_4->value());
    int rangedSurgeBuff = 0;
    //int aimUpgBuff = 3*(ui->skillBox_1->value());
    int alacBuff = 2*(ui->skillBox_6->value());
    if(ui->skillBox_5->value()==2) alacBuff += 5;

    stats2.at(TECH_CRIT_CHANCE) = ( TechCritChance(stats2, critBuff, true));
    stats2.at(TECH_CRIT_SIZE) = ( TechCritSize(stats2, techSurgeBuff));
    stats2.at(SPEED) =( Speed(stats2, alacBuff));
    stats2.at(MH_ACC) = (MH_Accuracy(stats2, accBuff));
    stats2.at(TECH_BONUS_DAMAGE) = TechBonusDamage(stats2, true);
    stats2.at(RANGED_CRIT_CHANCE) = ( RangedCritChance(stats2, critBuff, false));
    stats2.at(RANGED_CRIT_SIZE) = ( RangedCritSize(stats2, rangedSurgeBuff));
    stats2.at(RANGED_BONUS_DAMAGE) = RangedBonusDamage(stats2, false);
    return stats2;
}

void Vanguard::computeAlacrity(){
//    ui->castView->clear();
//    ui->countView->clear();
//    setStats();
//    vector <double> stats2=vanStats;
//    QString alacOutput = "Haste%, RSh SCG casts, RSh Casts, SCG usages, HSc+RSc casts, HSc+RSc SCG casts, Total Casts, HPS\n\n";
//    double rotationTime = ui->numCasts->value();
//    int numCasts = ui->numCasts->value();
//    double HPS;
//    for(double m=0.0;m<39.5;m+=0.5){
//        stats2.at(SPEED)=1-(m/100);
//        if(ui->fixedTimeButton->isChecked()){
//        HPS = bodyguardRotation(rotationTime,stats2);
//        }else{
//            HPS = bodyguardRotation(numCasts,stats2);
//        }
//        alacOutput += QString::number(m) +" , " + QString::number(RSh_SCG_count) +" ,  " + QString::number(RSh_count)
//                +" , " + QString::number(SCG_count)+" , " + QString::number(RSc_count+HSc_count)
//                + " , " + QString::number(RSc_SCG_count + HSc_SCG_count)+ " , " + QString::number(RSc_count + HSc_count+ES_count + RSh_count)
//                +" , " + QString::number(HPS) +"\n";
//    }
//    ui->countView->insertPlainText(alacOutput);
}

void Vanguard::updateStatBoxes()
{

    setStats();
    ui->techCritChanceLabel->setText(QString::number(vanStats.at(TECH_CRIT_CHANCE)));
    ui->techCritSizeLabel->setText(QString::number(vanStats.at(TECH_CRIT_SIZE)));
    ui->rangedCritChanceLabel->setText(QString::number(vanStats.at(RANGED_CRIT_CHANCE)));
    ui->rangedCritSizeLabel->setText(QString::number(vanStats.at(RANGED_CRIT_SIZE)));
    ui->speedLabel->setText(QString::number(100*(1-vanStats.at(SPEED))));
    ui->MHaccLabel->setText(QString::number(vanStats.at(MH_ACC)));
    ui->techBonusDamageLabel->setText(QString::number(vanStats.at(TECH_BONUS_DAMAGE)));
    ui->rangedBonusDamageLabel->setText(QString::number(vanStats.at(RANGED_BONUS_DAMAGE)));

    ui->primaryBox->setEnabled(true);
    ui->secondaryBox->setEnabled(true);
    ui->powerBox->setEnabled(true);
    ui->techBox->setEnabled(true);
    ui->critBox->setEnabled(true);
    ui->surgeBox->setEnabled(true);
    ui->alacBox->setEnabled(true);
    ui->accBox->setEnabled(true);
    ui->accBox_2->setEnabled(true);
    ui->accBox_3->setEnabled(true);
    ui->accuracyButton->setEnabled(true);
    ui->accLabel->setEnabled(true);
    ui->accLabel_2->setEnabled(true);
    ui->accLabel_3->setEnabled(true);
    ui->accWeightLabel->setEnabled(true);
    ui->MHaccLabel->setEnabled(true);
    ui->MHmaxBox->setEnabled(true);
    ui->MHmaxLabel->setEnabled(true);
    ui->MHminBox->setEnabled(true);
    ui->MHminLabel->setEnabled(true);
    ui->enemyArmorBox->setEnabled(true);
    ui->enemyArmorLabel->setEnabled(true);
    ui->enemyLevelBox->setEnabled(true);
    ui->enemyLevelLabel->setEnabled(true);
    ui->armorBox->setEnabled(false);
    ui->armorLabel->setEnabled(false);
    ui->defBox->setEnabled(false);
    ui->defLabel->setEnabled(false);
    ui->shieldBox->setEnabled(false);
    ui->shieldLabel->setEnabled(false);
    ui->absorbBox->setEnabled(false);
    ui->absorbLabel->setEnabled(false);
    ui->calcDPSButton->setText("Calculate DPS");
    ui->DPSlabel_1->setText("DPS");

    ui->powerButton->setText("Power");
    ui->aimButton->setText("Aim");
    ui->critButton->setText("Crit");
    ui->surgeButton->setText("Surge");
    ui->accuracyButton->setVisible(true);
    ui->alacrityButton->setVisible(true);

    ui->upg1Label->setText("Item 1 DPS: ");
    ui->upg2Label->setText("Item 2 DPS: ");

    if(ui->tree1->isChecked()){
        ui->primaryBox->setEnabled(false);
        ui->secondaryBox->setEnabled(false);
        ui->powerBox->setEnabled(false);
        ui->techBox->setEnabled(false);
        ui->critBox->setEnabled(false);
        ui->surgeBox->setEnabled(false);
        ui->alacBox->setEnabled(false);
        ui->accBox->setEnabled(false);
        ui->accBox_2->setEnabled(false);
        ui->accBox_3->setEnabled(false);
        ui->accuracyButton->setEnabled(false);
        ui->accLabel->setEnabled(false);
        ui->accLabel_2->setEnabled(false);
        ui->accLabel_3->setEnabled(false);
        ui->accWeightLabel->setEnabled(false);
        ui->MHaccLabel->setEnabled(false);
        ui->MHmaxBox->setEnabled(false);
        ui->MHmaxLabel->setEnabled(false);
        ui->MHminBox->setEnabled(false);
        ui->MHminLabel->setEnabled(false);
        ui->enemyArmorBox->setEnabled(false);
        ui->enemyArmorLabel->setEnabled(false);
        ui->enemyLevelBox->setEnabled(true);
        ui->enemyLevelLabel->setEnabled(true);
        ui->armorBox->setEnabled(true);
        ui->armorLabel->setEnabled(true);
        ui->defBox->setEnabled(true);
        ui->defLabel->setEnabled(true);
        ui->shieldBox->setEnabled(true);
        ui->shieldLabel->setEnabled(true);
        ui->absorbBox->setEnabled(true);
        ui->absorbLabel->setEnabled(true);
        ui->calcDPSButton->setText("Calculate Mitigation");
        ui->DPSlabel_1->setText("Mitigation");

//        ui->forceTechButton->setEnabled(false);
//        ui->shadowTechButton->setEnabled(false);
//        ui->combatTechButton->setEnabled(true);
//        ui->combatTechButton->setChecked(true);

        ui->powerButton->setText("Armor");
        ui->aimButton->setText("Defense");
        ui->critButton->setText("Shield");
        ui->surgeButton->setText("Absorb");
        ui->accuracyButton->setVisible(false);
        ui->alacrityButton->setVisible(false);

        ui->skill_label_8->setVisible(false);
        ui->skillBox_8->setVisible(false);
        ui->skill_label_9->setVisible(false);
        ui->skillBox_9->setVisible(false);
        ui->skill_label_10->setVisible(false);
        ui->skillBox_10->setVisible(false);

        ui->optionBox_1->setVisible(false);
        ui->optionLabel->setVisible(false);
        ui->optionLabel_1_2->setVisible(false);
        ui->optionBox_2->setVisible(false);
        ui->optionLabel_2->setVisible(false);
        ui->optionBox_3->setVisible(false);
        ui->optionLabel_3->setVisible(false);
        ui->optionBox_4->setVisible(false);
        ui->optionLabel_4->setVisible(false);
        ui->optionLabel_4_2->setVisible(false);

        ui->upg1Label->setText("Item 1 Mitigation: ");
        ui->upg2Label->setText("Item 2 Mitigation: ");

        getMitigation(0,0,0,0);
    }

    if(ui->tree2->isChecked()){

//        ui->forceTechButton->setEnabled(true);
//        ui->shadowTechButton->setEnabled(true);
//        ui->combatTechButton->setEnabled(false);
//        ui->shadowTechButton->setChecked(true);
    }
    if(ui->tree3->isChecked()){

//        ui->forceTechButton->setEnabled(true);
//        ui->shadowTechButton->setEnabled(true);
//        ui->combatTechButton->setEnabled(false);
//        ui->forceTechButton->setChecked(true);
    }
}

double Vanguard::getMitigation(int d_armor, int d_def, int d_shield, int d_absorb){

//    double base_DR = 1*(ui->skillBox_7->value()) + 5*(ui->skillBox_1->value());
//    double base_armor_mult = 1 + 0.2*(ui->skillBox_6->value());
//    if(ui->combatTechButton->isChecked()){ base_armor_mult+= 1.558;}
//        double base_def_per = 15 + 2*(ui->skillBox_3->value()) + 1*(ui->skillBox_4->value());
//        double base_shld_per = 5 + 15*(ui->skillBox_2->value());
//        if(ui->combatTechButton->isChecked()){ base_shld_per+= 15;}
//        double base_abs_per = 20 + 2*(ui->skillBox_5->value());

//        if((ui->check2pcBox->isChecked())&&(ui->skillBox_2->value()>0)){
//            base_shld_per += 5;
//        }
//        if(ui->check4pcBox->isChecked()){
//            base_DR += 2;
//        }
    double base_DR;
    double base_armor_mult;
    double base_def_per;
    double base_shld_per;
    double base_abs_per;
        base_DR = 9;
        base_armor_mult = 1.775;
        base_def_per = 5;
        base_shld_per = 32;
        base_abs_per = 26;

        double attLevel = ui->enemyLevelBox->value();
        double level = ui->levelBox->value();
        double attAcc = 1+0.05*(attLevel-level), attCrit = 0.1, attSurge = 0.5;
        double genShield = 0, genAbsorb = 0;

        double armor = ui->armorBox->value() + d_armor*base_armor_mult;
        double defense_rating = ui->defBox->value() + d_def;
        double shield_rating = ui->shieldBox->value() + d_shield;
        double absorb_rating = ui->absorbBox->value()+d_absorb;

        double armorDR= Armor(level, base_DR, armor);
        double defense = Defense(level, base_def_per, defense_rating);
        double shield = Shield(level, base_shld_per, shield_rating, genShield);
        double absorb = Absorb(level, base_abs_per, absorb_rating, genAbsorb);
        double mitigation = 100*(1 - ((min(attAcc - defense, 1.0)) * (1 - armorDR / 100)*(attCrit * (1 + attSurge) + min(shield, 1 - attCrit)*(1 - absorb) + max(1 - shield - attCrit, 0.0))));

        ui->defChanceBox->setText(QString::number(100*defense));
        ui->armor_DR_box->setText(QString::number(100*armorDR));
        ui->absorbPercentBox->setText(QString::number(100*absorb));
        ui->shieldChanceBox->setText(QString::number(100*shield));
        ui->DPS_label->setText(QString::number(mitigation));

        return mitigation;
}

double Vanguard::calculateDPS(){
    double DPS = 0;
    setStats();
    if(ui->tree1->isChecked()){
        double mit = getMitigation(0,0,0,0);

        ui->countView->insertPlainText(QString::number(mit));
    }
//    double rotationTime = ui->numCasts->value();
//    int numCasts = ui->numCasts->value();
//    if(ui->fixedTimeButton->isChecked()){
//    //    DPS = bodyguardRotation(rotationTime, shStats);
//    }else{
//    //    DPS = bodyguardRotation(numCasts, shStats);
//    }

    return DPS;
}

void Vanguard::getWeights(){
    //copy stats for modification
    setStats();
    vector <double> stats2 = vanStats;
    double baseDPS, aimDPS, cunningDPS, powerDPS, critDPS, surgeDPS, alacDPS =0, refStat=1;

    double statBuff = 1+0.03*(ui->skillBox_1->value());
    std::vector <double> weights(8,0);
    for(int m=0;m<7;m++){
        stats2 = vanStats;
        switch(m){
        case 0:
            break;
        case 1:
            stats2.at(AIM)+= (1*statBuff);
            break;
        case 2:
            stats2.at(POWER)+=1;
            break;
        case 3:
            stats2.at(CRIT)+=1;
            break;
        case 4:
            stats2.at(SURGE)+=1;
            break;
        case 5:
            stats2.at(ALACRITY)+=1;
            break;
        case 6:
            stats2.at(CUNNING)+=1;
            break;
        default:
            break;
        }
        stats2 = calculateStats(stats2);
        if(ui->fixedTimeButton->isChecked()){
            double numCasts = ui->numCasts->value();
        //    weights.at(m)=bodyguardRotation(numCasts, stats2);
        }else{
            int numCasts = ui->numCasts->value();
         //   weights.at(m)=bodyguardRotation(numCasts, stats2);
        }

    }
    baseDPS = weights.at(0);
    aimDPS = weights.at(1) -baseDPS;
    powerDPS = weights.at(2) -baseDPS;
    critDPS = weights.at(3) -baseDPS;
    surgeDPS = weights.at(4) -baseDPS;
    alacDPS = weights.at(5) -baseDPS;
    cunningDPS = weights.at(6) -baseDPS;

    if(ui->powerButton->isChecked())refStat = powerDPS;
    if(ui->aimButton->isChecked())refStat = aimDPS;
    if(ui->critButton->isChecked())refStat = critDPS;
    if(ui->surgeButton->isChecked())refStat = surgeDPS;
    if(ui->alacrityButton->isChecked())refStat = alacDPS;
    //if(ui->accuracyButton->isChecked())refStat = accuracyDPS;

    double powerWeight = powerDPS/refStat;
    double aimWeight = aimDPS/refStat;
    double cunningWeight = cunningDPS/refStat;
    double critWeight = critDPS/refStat;
    double surgeWeight = surgeDPS/refStat;
    double alacWeight = alacDPS/refStat;

    ui->critWeightLabel->setText(QString::number(critWeight));
    ui->surgeWeightLabel->setText(QString::number(surgeWeight));
    ui->alacWeightLabel->setText(QString::number(alacWeight));
    ui->powerWeightLabel->setText(QString::number(powerWeight));
    ui->primaryWeightLabel->setText(QString::number(aimWeight));
    ui->secondaryWeightLabel->setText(QString::number(cunningWeight));

    if(ui->tree1->isChecked()){
        double armor = getMitigation(100, 0, 0, 0) - getMitigation(0, 0, 0, 0);
        double def = getMitigation(0, 1, 0, 0) - getMitigation(0, 0, 0, 0);
        double shield = getMitigation(0, 0, 1, 0) - getMitigation(0, 0, 0, 0);
        double absorb = getMitigation(0, 0, 0, 1) - getMitigation(0, 0, 0, 0);

        double refStat;
        if(ui->powerButton->isChecked())refStat = armor;
        if(ui->aimButton->isChecked())refStat = def;
        if(ui->critButton->isChecked())refStat = shield;
        if(ui->surgeButton->isChecked())refStat = absorb;

        double armorWeight = armor/refStat;
        double defenseWeight = def/refStat;
        double shieldWeight = shield/refStat;
        double absorbWeight = absorb/refStat;
        ui->armorWeightLabel->setText(QString::number(armorWeight));
        ui->defenseWeightLabel->setText(QString::number(defenseWeight));
        ui->shieldWeightLabel->setText(QString::number(shieldWeight));
        ui->absorbWeightLabel->setText(QString::number(absorbWeight));

    }
}

void Vanguard::compareUpgrades(){
    setStats();
    vector <double> stats1 = vanStats;
    vector <double> stats2 = vanStats;
    double baseDPS = 0, upg1DPS = 1, upg2DPS = 2;
    if((ui->tree2->isChecked())||(ui->tree3->isChecked())){
    double rotationTime = ui->numCasts->value();
    int numCasts = ui->numCasts->value();

    double statBuff = 1 + 0.03*(ui->skillBox_1->value());
    if(ui->consularCheckBox->isChecked()) statBuff += 0.05;

    if(ui->fixedTimeButton->isChecked()){
    //    baseDPS = bodyguardRotation(rotationTime, shStats);
    }else{
    //    baseDPS = bodyguardRotation(numCasts, shStats);
    }
    //populate upgrade 1
    stats1.at(AIM) += (ui->primaryBox_2->value())*statBuff;
    stats1.at(CUNNING) += ui->secondaryBox_2->value();
    stats1.at(CRIT) += ui->critBox_2->value();
    stats1.at(SURGE) += ui->surgeBox_2->value();
    stats1.at(POWER) += ui->powerBox_2->value() + ui->techBox_2->value();
    stats1.at(ALACRITY) += ui->alacBox_2->value();

    stats1 = calculateStats(stats1);

    if(ui->fixedTimeButton->isChecked()){
    //    upg1DPS = bodyguardRotation(rotationTime, stats1);
    }else{
    //    upg1DPS = bodyguardRotation(numCasts, stats1);
    }

    //populate upgrade 2
    stats2.at(AIM) += (ui->primaryBox_3->value())*statBuff;
    stats2.at(CUNNING) += ui->secondaryBox_3->value();
    stats2.at(CRIT) += ui->critBox_3->value();
    stats2.at(SURGE) += ui->surgeBox_3->value();
    stats2.at(POWER) += ui->powerBox_3->value() + ui->techBox_2->value();
    stats2.at(ALACRITY) += ui->alacBox_3->value();

    stats2 = calculateStats(stats2);
    if(ui->fixedTimeButton->isChecked()){
    //    upg2DPS = bodyguardRotation(rotationTime, stats2);
    }else{
    //    upg2DPS = bodyguardRotation(numCasts, stats2);
    }

    upg1DPS -= baseDPS;
    upg2DPS -= baseDPS;
    ui->DPSlabel_2->setText(QString::number(upg1DPS));
    ui->DPSlabel_3->setText(QString::number(upg2DPS));

    if(upg1DPS == upg2DPS) ui->upg3Label->setText("No difference");
    if(upg1DPS > upg2DPS) ui->upg3Label->setText("Use Item 1");
    if(upg1DPS < upg2DPS) ui->upg3Label->setText("Use Item 2");
    }
    if(ui->tree1->isChecked()){
        double d_armor = ui->armorBox_2->value();
        double d_def = ui->defBox_2->value();
        double d_absorb = ui->absorbBox_2->value();
        double d_shield = ui->shieldBox_2->value();
        double mitigation1 = getMitigation(d_armor, d_def, d_shield, d_absorb) - getMitigation(0, 0, 0, 0);
        ui->DPSlabel_2->setText(QString::number(mitigation1));
        d_armor = ui->armorBox_3->value();
        d_def = ui->defBox_3->value();
        d_absorb = ui->absorbBox_3->value();
        d_shield = ui->shieldBox_3->value();
        double mitigation2 = getMitigation(d_armor, d_def, d_shield, d_absorb) - getMitigation(0, 0, 0, 0);
        ui->DPSlabel_3->setText(QString::number(mitigation2));
        if(mitigation1 == mitigation2) ui->upg3Label->setText("No difference");
        if(mitigation1 > mitigation2) ui->upg3Label->setText("Use Item 1");
        if(mitigation1 < mitigation2) ui->upg3Label->setText("Use Item 2");
    }
}

void Vanguard::on_primaryBox_editingFinished()
{
    updateStatBoxes();
}

void Vanguard::on_powerBox_editingFinished()
{
    updateStatBoxes();
}

void Vanguard::on_critBox_editingFinished()
{
    updateStatBoxes();
}

void Vanguard::on_alacBox_editingFinished()
{
    updateStatBoxes();
}

void Vanguard::on_levelBox_editingFinished()
{
    updateStatBoxes();
}

void Vanguard::on_secondaryBox_editingFinished()
{
    updateStatBoxes();
}

void Vanguard::on_techBox_editingFinished()
{
    updateStatBoxes();
}

void Vanguard::on_surgeBox_editingFinished()
{
    updateStatBoxes();
}

void Vanguard::on_accBox_editingFinished()
{
    updateStatBoxes();
}

void Vanguard::on_MHmaxBox_editingFinished()
{
    updateStatBoxes();
}

void Vanguard::on_MHminBox_editingFinished()
{
    updateStatBoxes();
}

void Vanguard::on_enemyLevelBox_editingFinished()
{
    updateStatBoxes();
}

void Vanguard::on_enemyArmorBox_editingFinished()
{
    updateStatBoxes();
}

void Vanguard::on_calcWeightButton_clicked()
{
    updateStatBoxes();
    getWeights();
}

void Vanguard::on_upgradeButton_clicked()
{
    compareUpgrades();
}

void Vanguard::on_check4pcBox_toggled(bool checked)
{
    if(checked==true) ui->check2pcBox->setChecked(true);
}

void Vanguard::on_check2pcBox_toggled(bool checked)
{
    if(checked==false) ui->check4pcBox->setChecked(false);
}


void Vanguard::on_computeAlacrityButton_clicked()
{
    computeAlacrity();
}

void Vanguard::on_skillBox_1_editingFinished()
{
    updateStatBoxes();
}

void Vanguard::on_skillBox_2_editingFinished()
{
    updateStatBoxes();
}

void Vanguard::on_skillBox_3_editingFinished()
{
    updateStatBoxes();
}

void Vanguard::on_skillBox_4_editingFinished()
{
    updateStatBoxes();
}

void Vanguard::on_skillBox_5_editingFinished()
{
    updateStatBoxes();
}

void Vanguard::on_skillBox_6_editingFinished()
{
    updateStatBoxes();
}

void Vanguard::on_skillBox_7_editingFinished()
{
    updateStatBoxes();
}

void Vanguard::on_skillBox_8_editingFinished()
{
    updateStatBoxes();
}

void Vanguard::on_skillBox_9_editingFinished()
{
    updateStatBoxes();
}

void Vanguard::on_note1_clicked()
{
    ui->countView->clear();
    QString note1 = "*Note that Crit Size may differ from the value in game because Warden only affects heals, so does not show up on the in-game tooltip.";
    ui->countView->insertPlainText(note1);
}

void Vanguard::on_note2_clicked()
{
    ui->countView->clear();
    QString note2 = "**Note 2: Alacrity has complex interactions with SCG windows, resource mechanics, Effective Cost of abilities, etc.\n\n Current recommendation is for 5-7.5% Alacrity, not to exceed 8.5% for Commandos or 12.5% for Mercs. The difference is due to imbalance in their resource regen windows.  While Alacrity is not good for Mercs, it is especially bad for Commandos.\n\n For more information, see the following two threads on the SWTOR.com forums\n\n http://www.swtor.com/community/showthread.php?p=2900243#post2900243\n\nhttp://www.swtor.com/community/showthread.php?t=306667";
    ui->countView->insertPlainText(note2);
}

void Vanguard::on_saveStats_clicked()
{
    setStats();
    string filename = "Vanguard_stats.txt";
    ofstream fout (filename.c_str());
    fout << vanStats.at(AIM) << "\n" << vanStats.at(CUNNING) << "\n" << vanStats.at(CRIT)<< "\n" <<
            vanStats.at(SURGE) << "\n" << ui->powerBox->value() << "\n" << ui->techBox->value() << "\n" << vanStats.at(ALACRITY) << "\n" <<
    vanStats.at(LEVEL) << "\n" << vanStats.at(ACCURACY) << "\n" << vanStats.at(MH_MAX) << "\n" <<
    vanStats.at(MH_MIN) << "\n" << vanStats.at(ENEMY_LEVEL) << "\n" << vanStats.at(ENEMY_ARMOR) << endl;

    fout << ui->skillBox_1->value() << "\n" << ui->skillBox_2->value() << "\n" << ui->skillBox_3->value() << "\n" <<
            ui->skillBox_4->value() << "\n" << ui->skillBox_5->value() << "\n" << ui->skillBox_6->value() << "\n" <<
            ui->skillBox_7->value() << "\n" << ui->skillBox_8->value() << "\n" << ui->skillBox_9->value() << "\n" << endl;

    fout << vanStats.at(OH_MAX) << "\n" << vanStats.at(OH_MIN) << endl;
    fout.close();
}

void Vanguard::on_loadStats_clicked()
{
    Load_Stats();
}

void Vanguard::Load_Stats(){
    string filename = "Vanguard_stats.txt";
    ifstream fin (filename.c_str());
    vector <string> inputStats(27,"0");
    int i=0;
    while(fin.good()){
        getline(fin,inputStats.at(i));
                i++;
    }
    ui->primaryBox->setValue(atoi(inputStats.at(0).c_str()));
    ui->secondaryBox->setValue(atoi(inputStats.at(1).c_str()));
    ui->critBox->setValue(atoi(inputStats.at(2).c_str()));
    ui->surgeBox->setValue(atoi(inputStats.at(3).c_str()));
    ui->powerBox->setValue(atoi(inputStats.at(4).c_str()));
    ui->techBox->setValue(atoi(inputStats.at(5).c_str()));
    ui->alacBox->setValue(atoi(inputStats.at(6).c_str()));
    ui->levelBox->setValue(atoi(inputStats.at(7).c_str()));
    ui->accBox->setValue(atoi(inputStats.at(8).c_str()));
    ui->MHmaxBox->setValue(atoi(inputStats.at(9).c_str()));
    ui->MHminBox->setValue(atoi(inputStats.at(10).c_str()));
    ui->enemyLevelBox->setValue(atoi(inputStats.at(11).c_str()));
    ui->enemyArmorBox->setValue(atoi(inputStats.at(12).c_str()));

//set skill boxes
    ui->skillBox_1->setValue(atoi(inputStats.at(13).c_str()));
    ui->skillBox_2->setValue(atoi(inputStats.at(14).c_str()));
    ui->skillBox_3->setValue(atoi(inputStats.at(15).c_str()));
    ui->skillBox_4->setValue(atoi(inputStats.at(16).c_str()));
    ui->skillBox_5->setValue(atoi(inputStats.at(17).c_str()));
    ui->skillBox_6->setValue(atoi(inputStats.at(18).c_str()));
    ui->skillBox_7->setValue(atoi(inputStats.at(19).c_str()));
    ui->skillBox_8->setValue(atoi(inputStats.at(20).c_str()));
    ui->skillBox_9->setValue(atoi(inputStats.at(21).c_str()));

    fin.close();
}

void Vanguard::on_tree1_clicked()
{
    updateStatBoxes();
}

void Vanguard::on_tree2_clicked()
{
    updateStatBoxes();
}

void Vanguard::on_tree3_clicked()
{
    updateStatBoxes();
}
